#ifndef YHAIDA_EVENTLOOPTHREADPOOL_H
#define YHAIDA_EVENTLOOPTHREADPOOL_H
#include "../base/Utils.h"
#include "../thread/Thread.h"
#include "../mutex/MutexLock.h"
#include "../mutex/Condition.h"
#include <functional>
#include <memory>
#include <vector>
namespace yhaida
{
    class EventLoop;
    class EventLoopThread;

    class EventLoopThreadPool : Utils::nocapyable
    {
    public:
        typedef std::function<void(EventLoop *)> ThreadInitCallback;
    public:
        EventLoopThreadPool(EventLoop *baseLoop);
        ~EventLoopThreadPool();

        void setThreadNum(int numThreads) { _numThreads = numThreads; }

        void start(const ThreadInitCallback &cb = ThreadInitCallback());

        EventLoop *getNextLoop();

    private:
        EventLoop *_baseLoop;
        bool _started;
        int _numThreads;
        int _next;
        std::vector<std::unique_ptr<EventLoopThread>> _threads;
        std::vector<EventLoop *> _loops;
    };
}

#endif